package com.hqyj.controller;

import com.hqyj.pojo.User;
import com.hqyj.service.LoginService;
import com.hqyj.service.UserService;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;

@RequestMapping("/login")
@Controller
public class LoginController {

    @Autowired
    LoginService loginService;

    @Autowired
    UserService userService;

    //访问注册页面
    @RequestMapping("/registPage")
    public String registPage(){
        return "admin/regist";
    }

    //发送验证码
    @RequestMapping("/sendCodeAjx")
    @ResponseBody
    public HashMap<String,Object> sendCode(String email, HttpServletRequest request){
        return loginService.sendCode(email,request);
    }

    //邮件登录
    @RequestMapping("/email")
    @ResponseBody
    public HashMap<String,Object> email(String code, HttpServletRequest request){
        return loginService.loginEmail(code,request);
    }

    //shiro登录
    @RequestMapping("/loginShiro")
    @ResponseBody
    public HashMap<String,Object> loginShiro(User user,HttpServletRequest request){

        return  userService.login(user,request);
    }

    //注册功能
    @RequestMapping("/regist")
    @ResponseBody
    public HashMap<String,Object> regist(User user,HttpServletRequest request) {
        return userService.regist(user,request);
    }
}
